package aspectos;


import java.util.HashMap;


import annotations.Monitored;



public aspect ContadorLlamadasPerInstanceAspect pertarget(initialization(dominio..new(..)))  {
	
	public HashMap<String,Integer> map = new HashMap<String,Integer>();
	
	pointcut monitoringCatch(Object target):
		call(@Monitored * *(..))&& target(target);
	
	before(Object target):monitoringCatch(target){
		agregarConteoAlMap(thisJoinPoint.getSignature().getName());
	}
	
	public int cantLlamadas(String st){
		if(map.containsKey(st)){
			return map.get(st);
		}else{
			return 0;
		}
		
	}
	
	protected void agregarConteoAlMap(String source) {
		
		if(map.containsKey(source)){
			
			Integer tmp = map.get(source);
			map.put(source, tmp + 1);
		} else {
			map.put(source, 1);
		}

		
	}
	

}
